package com.zt.location.common.utils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import com.zt.location.modules.base.entity.LimitspeedEntity;
import com.zt.location.modules.business.message.TaskData;

public class SysCache {

	private static ConcurrentHashMap<String,Object> conMap = new ConcurrentHashMap<String,Object>();
	
	private static ConcurrentHashMap<String,TaskData> machineAllMap = new ConcurrentHashMap<String,TaskData>();
	
	private static ConcurrentHashMap<Integer,LimitspeedEntity> limitSpeedMap = new ConcurrentHashMap<Integer,LimitspeedEntity>();
	
	private static ConcurrentHashMap<String,String> lastUpdateTime = new ConcurrentHashMap<String,String>();
	
	public static void addObject(String key,Object val){
		conMap.put(key, val);
	}
	
	public static Object getObject(String key){
		return conMap.get(key);
	} 
	
	public static Object delObject(String key){
		return conMap.remove(key); 
	}
	
	public static boolean isExites(String key){ 
		return conMap.containsKey(key); 
	}
	
	public static Object delObject(Object val){
		 for (Map.Entry<String, Object> entry : conMap.entrySet()) {
			if(entry.getValue().equals(val)){
				return conMap.remove(entry.getKey()); 
			}
		 }
		return null;
	} 
	
	
	public static void addMachineObject(String key,TaskData val){
		machineAllMap.put(key, val);
	}
	
	public static TaskData getMachineObject(String key){
		return machineAllMap.get(key);
	}
	
	public static List<TaskData> getMachineAll(){
		return new ArrayList<TaskData>(machineAllMap.values());
	}
	 
	
	public static void setLimitSpeed(List<LimitspeedEntity> limitSpeedList){
		for(LimitspeedEntity limitSpeed:limitSpeedList){
			int startPos = (Integer.valueOf(limitSpeed.getBeginpoint())-13000)/100;
			int endPos =(Integer.valueOf(limitSpeed.getEndpoint())-13000)/100; 
			for(int i=startPos;i<=endPos;i++){
				limitSpeedMap.put(i, limitSpeed);	
			} 
		} 
	}
	
	public static LimitspeedEntity getLimitSpeed(int pos){
		return  limitSpeedMap.get(pos);
	} 
	
	public static void setMaichUpdateTime(String machineKey,String udpateTime){
		lastUpdateTime.put(machineKey, udpateTime);
	}
	
	public static String getMaichUpdateTime(String machineKey){
		return lastUpdateTime.get(machineKey);
	}
	
}
